package com.shlg.chuang.repository;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.shlg.chuang.domain.Content;
import com.shlg.chuang.domain.ContextType;

public interface ContentRepository extends JpaRepository<Content, Long>{

	@Query("select c from Content c where sqrt((c.latitude - :localLatitude)*(c.latitude - :localLatitude)+(c.longitude - :localLongitude)*(c.longitude - :localLongitude))< :scope")
	List<Content> searchLatitudeSquAndLongitudeSquLessThanScope(@Param("localLatitude")Double localLatitude,
			@Param("localLongitude")Double localLongitude, @Param("scope")Double scope); 
	
	@Query("select c from Content c where (c.contextType = :contextType) and (sqrt((c.latitude - :localLatitude)*(c.latitude - :localLatitude)+(c.longitude - :localLongitude)*(c.longitude - :localLongitude))< :scope)")
	List<Content> filterByContentType(@Param("contextType") ContextType contextType, 
			@Param("localLatitude")Double localLatitude,
			@Param("localLongitude")Double localLongitude, 
			@Param("scope") Double scope);
	
	List<Content> findByShowUserId(Long showUserId);
}
